package com.budwk.app.enterprise.services.impl;

import com.budwk.app.enterprise.models.WarehouseLogistics;
import com.budwk.app.enterprise.services.WarehouseLogisticsService;
import com.budwk.starter.common.page.PageUtil;
import com.budwk.starter.common.page.Pagination;
import com.budwk.starter.database.service.BaseServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.dao.util.cri.SqlExpressionGroup;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.Strings;

@IocBean(args = {"refer:dao"})
public class WarehouseLogisticsServiceImpl extends BaseServiceImpl<WarehouseLogistics> implements WarehouseLogisticsService {
    public WarehouseLogisticsServiceImpl(Dao dao) {
        super(dao);
    }

    @Override
    public Pagination listByPage(WarehouseLogistics bean) {
        Cnd cnd = Cnd.NEW();
        SqlExpressionGroup sqlGroup = cnd.where();
        if (Strings.isNotBlank(bean.getPageOrderName()) && Strings.isNotBlank(bean.getPageOrderBy())) {
            cnd.orderBy(bean.getPageOrderName(), PageUtil.getOrder(bean.getPageOrderBy()));
        }
        if (StringUtils.isNotEmpty(bean.getStorageLocation())) {
            sqlGroup.andLike(WarehouseLogistics::getStorageLocation, bean.getStorageLocation());
        }
        if (StringUtils.isNotEmpty(bean.getInventory())) {
            sqlGroup.andLike(WarehouseLogistics::getInventory, bean.getInventory());
        }
        if (StringUtils.isNotEmpty(bean.getLogisticsMethods())) {
            sqlGroup.andLike(WarehouseLogistics::getLogisticsMethods, bean.getLogisticsMethods());
        }
        if (StringUtils.isNotEmpty(bean.getTransportVehicles())) {
            sqlGroup.andLike(WarehouseLogistics::getTransportVehicles, bean.getTransportVehicles());
        }
        if (StringUtils.isNotEmpty(bean.getEntryExitWarehouse())) {
            sqlGroup.andLike(WarehouseLogistics::getEntryExitWarehouse, bean.getEntryExitWarehouse());
        }
        return this.listPage(bean.getPageNo(), bean.getPageSize(), cnd);
    }
}
